import React from 'react';
import {Form, Select, Input} from 'antd';
import { WeaBrowser } from 'ecCom';
const FormItem = Form.Item;
const Option = Select.Option;

import FormGroup from './base/FormGroup';
import FormItem4Title from './base/FormItem4Title';

// 搜索元素
export default class Content_searchengine extends React.Component {
    constructor(props) {
        super(props);
        this.onChange = this.onChange.bind(this);
    }
    onChange(ids,names,datas){
        this.props.data.eContent.eNewsFrom = datas;
        this.props.form.setFieldsValue({'eContentNewsFrom': ids});
    }
    render() {
        const { eShareLevel, eContent } = this.props.data;
        const { eNewsFrom,eNewsMould } = eContent;
        const { getFieldProps,setFieldsValue } = this.props.form;
        const { formItemLayout } = this.props;
        let eFormItem4NewsFrom = <div></div>;
        let eFormItem4NewsMould = <div></div>;
        if (eShareLevel == '2') {
            getFieldProps('eContentNewsFrom', {initialValue: eNewsFrom.length ? eNewsFrom[0].id : ''});
            eFormItem4NewsFrom = (
                <FormItem label="新闻来源" {...formItemLayout}>
                    <div style={{display: 'inline-block', width: '350px', margin: '5px', verticalAlign: 'middle'}}>
                        <WeaBrowser
                            type={37}
                            isSingle={true}
                            replaceDatas={ eNewsFrom }
                            onChange={this.onChange}
                        />
                    </div>
                </FormItem>
            );
            const eNewsMouldProps = getFieldProps('eContentNewsMould', {initialValue: eNewsMould.selected});
            const eNewsModuleOptions = eNewsMould.options.map((item, index) => {
                return <Option key={index} value={item.key}>{item.value}</Option>;
            });
            eFormItem4NewsMould = (
                <FormItem label="新闻模板" {...formItemLayout}>
                    <Select size="default" style={{width: '200px'}} {...eNewsMouldProps}>
                        {eNewsModuleOptions}
                    </Select>
                </FormItem>
            );
        }

        return (
            <Form horizontal className="esetting-form">
                <FormGroup title="基本信息">
                    <FormItem4Title {...this.props}/>
                    {eFormItem4NewsFrom}
                    {eFormItem4NewsMould}
                </FormGroup>
            </Form>
        );
    }
}